#!/bin/bash
#version:v23.05.11
# cd ~ &&  wget -O  init.sh  https://gitee.com/thinkyoung/ENV/raw/master/Debian/pool/main/i/init/init.sh  &&  sudo bash init.sh

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
LANG=en_US.UTF-8



# 安装自定义alias
Alias(){
cd ~ 
sudo wget -O .bash_aliases https://gitee.com/thinkyoung/ENV/raw/master/Debian/pool/main/a/alias/.bash_aliases  
source  ~/.bash_aliases

echo -e "\033[33m $FUNCNAME \033[0m" 
}

# 添加自定义源
Source(){
# 添加自定义源：国内debian源
sudo wget -O debian.list https://gitee.com/thinkyoung/ENV/raw/master/Debian/pool/main/s/source/debian11/debian.list  
sudo  mv ./debian.list /etc/apt/sources.list.d/debian.list

echo -e "\033[33m $FUNCNAME \033[0m" 
}

# 安装输入法 Fcitx5
Fcitx5(){
# 1.安装输入法
sudo apt install --install-recommends fcitx5 fcitx5-chinese-addons
# 2.添加配置（修复浏览器无法正常输入问题）
# 在 /etc/environment 文件中配置环境变量，配置完成后，登出用户，重新登录。没有这个文件的时候需要手动创建。
echo 'GTK_IM_MODULE=fcitx' | sudo tee -a  /etc/environment
echo 'QT_IM_MODULE=fcitx' | sudo tee -a  /etc/environment
echo 'XMODIFIERS=@im=fcitx' | sudo tee -a  /etc/environment
echo 'INPUT_METHOD=fcitx' | sudo tee -a  /etc/environment
echo 'SDL_IM_MODULE=fcitx' | sudo tee -a  /etc/environment
# 3.添加软链接（修复需要手动启动输入法的问题）
mkdir ~/.config/autostart/
ln -s /usr/share/applications/org.fcitx.Fcitx5.desktop ~/.config/autostart/

echo -e "\033[33m $FUNCNAME \033[0m" 
}

# 更换自定义第三方优化内核
Kernel(){

sudo apt install console-setup
echo 'deb http://deb.xanmod.org releases main' | sudo tee /etc/apt/sources.list.d/xanmod-kernel.list
wget -qO - https://dl.xanmod.org/gpg.key | sudo apt-key --keyring /etc/apt/trusted.gpg.d/xanmod-kernel.gpg add -
sudo apt update && sudo apt install linux-xanmod

echo -e "\033[33m $FUNCNAME \033[0m" 
}



# 修改Grub
Grub(){
# 需要修改grub-cfg开机时间 以及 #自主降频
# 本脚本用来修改引导界面
#取消延时
sudo sed -i 's/GRUB_TIMEOUT=1/GRUB_TIMEOUT=0/g' /etc/default/grub
#取消主题
#sudo sed -i 's/GRUB_THEME/\#GRUB_THEME/g' /etc/default/grub #注释掉
sudo sed -i '/GRUB_BACKGROUND/d' /etc/default/grub #删除
sudo sed -i '/GRUB_THEME/d' /etc/default/grub #删除
#更新grub
sudo update-grub

echo -e "\033[33m $FUNCNAME \033[0m" 
}

# 安装驱动
Driver(){
#开启32位
#sudo dpkg --add-architecture i386
# sudo apt update
# sudo apt install  libdbus-glib-1-2
# sudo apt-get install libdbus-glib-1-2:i386

# 硬件信息
sudo apt install inxi

# 安装intel集成显卡
sudo  apt  install  libgl1-mesa-dri    mesa-vulkan-drivers    libvulkan1   vulkan-tools  vulkan-validationlayers
# sudo  apt  install  libgl1-mesa-dri:i386 mesa-vulkan-drivers:i386 libvulkan1:i386
echo -e "\033[33m $FUNCNAME \033[0m" 
}



# MX Linux 安装
MX(){
  
# 添加自定义源：国内mxlinux源
#sudo wget -O mx.list https://gitee.com/thinkyoung/ENV/raw/master/Debian/pool/main/s/source/mxlinux/mx.list  
#sudo  mv ./mx.list /etc/apt/sources.list.d/mx.list

# 安装mx-apps
#sudo apt install mx-apps


echo -e "\033[33m $FUNCNAME \033[0m" 
}


# 一键安装 装机必备
One(){
# 一键装机必备
sudo mkdir /data
sudo mount /dev/nvme0n1p5 /data
echo '/dev/nvme0n1p5 /data ext4 defaults 0 0' | sudo tee -a  /etc/fstab
sudo apt install /data/packages/deepinstore/pool/deepinstore/*.deb

echo -e "\033[33m $FUNCNAME \033[0m" 
}

Spark_store(){
# 安装星火商店 本地源里面已经有相同 省略
sudo apt install git qtbase5-dev debhelper pkg-config qtchooser libqt5core5a libqt5gui5 libqt5widgets5 libqt5network5 libqt5concurrent5 libdtkcore-dev libdtkgui-dev  libdtkwidget-dev qttools5-private-dev libnotify-dev qtwebengine5-dev

wget -O spark.deb https://gitee.com/deepin-community-store/spark-store/releases/download/txz/spark-store_3.3.3~test4_amd64.deb && sudo apt install ./spark.deb

echo -e "\033[33m $FUNCNAME \033[0m" 
}


# 优化开机加速，禁用服务：
Speed(){
sudo systemctl mask apt-daily.service
sudo systemctl mask apt-daily-upgrade.service
sudo systemctl mask nmbd.service
sudo systemctl mask plymouth-quit-wait.service
sudo systemctl mask NetworkManager-wait-online.service

# 关闭控制中心自动更新
busctl call com.deepin.lastore /com/deepin/lastore com.deepin.lastore.Updater SetAutoCheckUpdates b 0
busctl call com.deepin.lastore /com/deepin/lastore com.deepin.lastore.Updater SetAutoDownloadUpdates b 0
busctl call com.deepin.lastore /com/deepin/lastore com.deepin.lastore.Updater SetUpdateNotify b 0
busctl call com.deepin.lastore /com/deepin/lastore com.deepin.lastore.Manager SetAutoClean b 0

echo -e "\033[33m $FUNCNAME \033[0m" 
}

Beautify(){


# 设置自定义图标主题 Win11 本地源deb已经安装
wget -O deepinstore.win11.theme.deb https://gitee.com/thinkyoung/deepinstore.win11.icon.theme/releases/download/v22.10.01/deepinstore.win11.theme_22.10.01.deb && sudo apt install ./deepinstore.win11.theme.deb
gsettings set com.deepin.dde.appearance icon-theme Win11
gsettings set com.deepin.dde.dock display-mode 'efficient'  # dock-高效模式
gsettings set com.deepin.dde.dock window-size-efficient 42  # dock-高度增加

#sudo plymouth-set-default-theme win11 && sudo plymouth-set-default-theme -R win11


# 更换背景图片
dbus-send --session --print-reply=literal --dest=com.deepin.daemon.Appearance /com/deepin/daemon/Appearance   com.deepin.daemon.Appearance.SetMonitorBackground string:"DP-1" string:"file:///usr/share/wallpapers/deepin/mike-yukhtenko-a2kD4b0KK4s-unsplash.jpg"

echo -e "\033[33m $FUNCNAME \033[0m" 
}

Clean(){
#卸载旧内核
#sudo apt purge linux-headers-5.10.*-amd64-desktop ; linux-image-5.10.*-amd64-desktop
echo -e "\033[33m $FUNCNAME \033[0m" 
}

pause()
{
read -n1 -p "Press any key to continue..." 
}
Help(){
cat << EOF
[0][list][列表]  
[1][alias][别名]
[2][source][软件源]
[29][mx][MXLinux源]
[23][fcitx5][输入法]
[3][kernel][第三方内核]
[4][grub][启动优化]
[5][speed][加速]
[6][upgrade][升级]
[7][driver][驱动]
[8][spark-store][星火商店]
[10][one][安装]
[11][beautify][美化]
[12][clean][清理]
[99][all][全部]
EOF
}

Install_Main(){

	startTime=`date +%s`
	echo $startTime ;
	Alias;
	Source;
	#MX
	Fcitx5;
	Kernel;
	Grub;
	Speed;
	# 全面更新升级命令
	full-upgrade;
	Driver;
	Spark_store;
	#One
	Beautify;
	Clean;


}


reset 
echo "
+----------------------------------------------------------------------
| InitShell for Deepin
+----------------------------------------------------------------------
| Copyright © 2015-2099 ThinkYoung (https://gitee.com/thinkyoung) All rights reserved.
+----------------------------------------------------------------------
| Enjoy it when installed.
+----------------------------------------------------------------------
"
while [ "$go" != 'y' ] && [ "$go" != 'n' ]
do
	read -p "Do you want to install InitShell for Deepin now ? (y/n): " go;
done

if [ "$go" == 'n' ];then
	exit;
fi
if [ "$go" == 'y' ];then
	echo -e "\033[33m Start！！！ \033[0m"; 
fi


# 软件列表

while [ "$to" != 'exit' ] && [ "$to" != 'quit' ]
do
	Help;
	read -p "选择你要操作的命令(列表:输入list or 1  退出：输入exit or -1 ): " to;


if [  "$to" == 'list'  ] || [  "$to" == 'help'  ];then
	Help;
fi

if [ "$to" == 'alias' ];then
	Alias;
fi

if [ "$to" == 'source' ];then
	Source;
fi
if [ "$to" == 'mx' ];then
	MX;
fi
if [ "$to" == '23' ]  || [ "$to" == 'fcitx5' ];then
	Fcitx5;
fi
if [ "$to" == 'kernel' ];then
	Kernel;
fi

if [ "$to" == 'grub' ];then
	Grub;
fi

if [ "$to" == 'speed' ];then
	Speed;
fi

if [ "$to" == 'upgrade' ];then
	full-upgrade;
fi

if [ "$to" == 'driver' ];then
	Driver;
fi
if [ "$to" == 'spark' ];then
	Spark;
fi
if [ "$to" == 'spark-store' ];then
	Spark_store;
fi
if [ "$to" == 'one' ];then
	One;
fi

if [ "$to" == 'beautify' ];then
	Beautify;
fi

if [ "$to" == 'clean' ];then
	Clean;
fi
if [ "$to" == 'all' ];then
	Install_Main;
fi

if [ "$to" == 'exit' ] || [ "$to" == 'quit' ];then
	exit;
fi



done
#read -s "for auto install,password?" PASSWORD;
#export PASSWORD;
#Install_Main
